<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>key的原理</title>
		<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="root">
			<!-- 遍历数组 -->
			<h2>人员列表</h2>
			<button type="button" @click="add()">点击添加一个老刘</button>
			<ul>
				<li v-for="(person,index) in persons":key="person.id">
					{{index}} - {{person.name}} - {{person.age}}
				</li>
			</ul>
			
			
			
		</div>
		<script type="text/javascript">
			Vue.config.productionTip = false
			new Vue({
				el:"#root",
				data:{
					persons:[
						{
							id:"001",
							name:"张三",
							age:18
						},
						{
							id:"002",
							name:"李四",
							age:19
						},
						{
							id:"003",
							name:"王五",
							age:20
						}
						
					]
				},
				methods:{
					add(){
						const person = {
							id:"004",
							name:"老刘",
							age:40
						}
						this.persons.unshift(person)
						
					}
				}
			})
		</script>
	</body>
</html>
